/*
 * @author: Rushi Amin
 */
package FlowGram.Application.IDEWindow.FileHost;

import java.awt.Color;
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;

import javax.swing.BorderFactory;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JViewport;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;


import FlowGram.Application.Parser.FinchParser;
import FlowGram.Application.Parser.FinchProgramFlow;
import FlowGram.Application.Parser.Actions.FinchAction;
import FlowGram.Application.Parser.Actions.Control.ControlAction;
import FlowGram.Application.Parser.Actions.Control.If;

public class CodeEditor extends Editor {
	private JScrollPane codeEditorScrollPane;

	public CodeEditor(){
		JEditorPane codeEditorPane = new JEditorPane();
		codeEditorPane.setEditable(false);
		//Put the editor pane in a scroll pane.
		codeEditorScrollPane = new JScrollPane(codeEditorPane);
		codeEditorScrollPane.setVerticalScrollBarPolicy(
		                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		codeEditorScrollPane.setHorizontalScrollBarPolicy(
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		codeEditorScrollPane.setPreferredSize(new Dimension(400, 700));
		codeEditorScrollPane.setMinimumSize(new Dimension(400, 700));
		codeEditorScrollPane.setBorder(BorderFactory.createLineBorder (Color.blue, 2));
		codeEditorPane.setSize(codeEditorScrollPane.getSize());
		this.add(codeEditorScrollPane);
	}
	
	public int getCaretPosition(){
	return this.getCodeEditorPane().getCaretPosition();
	}
	
	public void setUpCodeEditor(FinchProgramFlow programFlow){
		String codeString = programFlow.toCode();
		this.getCodeEditorPane().setText(codeString);
		}
	
	public JEditorPane getCodeEditorPane(){
		JViewport viewport = codeEditorScrollPane.getViewport(); 
		JEditorPane codeEditorPane = (JEditorPane)viewport.getView();
		return codeEditorPane;
		
		
	}
	
	
	
	
}
